using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;

namespace Scalextric
{
    public class Checksum
    {
        public bool Valid { get; set; }
        public byte Check { get; set; }

        public Checksum(byte[] packet)
        {
            Check = Crc8.ComputeChecksum(packet);
            //now do check
            byte[] fullPacket = new byte[packet.Length + 1];
            packet.CopyTo(fullPacket, 0);
            //add checksum to end
            packet[packet.Length - 1] = Check;
            if (Crc8.ComputeChecksum(fullPacket) == 0)
                Valid = true;
            else
                Valid = false;
        }
    }
}
